import http from '@/util/http'

const module = {
  namespaced: true, // 命名空间
  state: {
    cover: '',
    columnList: [],
    columnNextIndex: 0
  },
  actions: {
    getColumnAction (store, fullPath) {
      http.request({
        url: `/api${fullPath}`
      }).then(res => {
        store.commit('setCover', res.data.data.cover) // 支持传参
      })
    },
    getColumnMore (store, params) {
      http.request({
        url: `/api${params.path}/items?start=${params.start}`
      }).then(res => {
        store.commit('pushColumnList', res.data.data.list)
        store.commit('setNextIndex', res.data.data.nextIndex)
      })
    },
    getColumnList (store, params) {
      http.request({
        url: `/api${params.path}/items?start=${params.start}`
      }).then(res => {
        store.commit('setColumnList', res.data.data.list)
        store.commit('setNextIndex', res.data.data.nextIndex)
      })
    }
  },
  mutations: {
    setCover (state, data) {
      console.log('cover', data)
      state.cover = data
    },
    pushColumnList (state, data) {
      console.log('pushColumnList', data)
      state.columnList.push(...data)
    },
    setColumnList (state, data) {
      console.log('setColumnList', data)
      state.columnList = data
    },
    setNextIndex (state, data) {
      console.log('columnNextIndex', data)
      state.columnNextIndex = data
    }
  }
}

export default module
